import { getFilePath } from "@linksaas-git/widget";

const langExtMap = new Map(Object.entries({
  "abap": 'abap',
  "g4": 'antlr4',
  "apl": 'apl',
  "dyalog": 'apl',
  "asp": 'aspnet',
  "asax": 'aspnet',
  "ascx": 'aspnet',
  "ashx": 'aspnet',
  "asmx": 'aspnet',
  "aspx": 'aspnet',
  "axd": 'aspnet',
  "as": 'actionscript',
  "adb": 'ada',
  "ada": 'ada',
  "ads": 'ada',
  "agda": 'agda',
  "apacheconf": 'apacheconf',
  "vhost": 'nginx',
  "cls": 'visual-basic',
  "applescript": 'applescript',
  "scpt": 'applescript',
  "ino": 'arduino',
  "asciidoc": 'asciidoc',
  "adoc": 'asciidoc',
  "asm": 'nasm',
  "a51": 'nasm',
  "nasm": 'nasm',
  "ahk": 'autohotkey',
  "ahkl": 'autohotkey',
  "au3": 'autoit',
  "awk": 'awk',
  "auk": 'awk',
  "gawk": 'awk',
  "mawk": 'awk',
  "nawk": 'awk',
  "bat": 'batch',
  "cmd": 'batch',
  "bison": 'bison',
  "brs": 'brightscript',
  "bro": 'bro',
  "c": 'c',
  "cats": 'c',
  "h": 'objectivec',
  "idc": 'c',
  "w": 'c',
  "cs": 'smalltalk',
  "cake": 'coffeescript',
  "cshtml": 'csharp',
  "csx": 'csharp',
  "cpp": 'cpp',
  "c++": 'cpp',
  "cc": 'cpp',
  "cp": 'pascal',
  "cxx": 'cpp',
  "h++": 'cpp',
  "hpp": 'cpp',
  "hxx": 'cpp',
  "inl": 'cpp',
  "ipp": 'cpp',
  "tcc": 'cpp',
  "tpp": 'cpp',
  "chs": 'haskell',
  "cmake": 'cmake',
  "cmake.in": 'cmake',
  "cob": 'cobol',
  "cbl": 'cobol',
  "ccp": 'cobol',
  "cobol": 'cobol',
  "cpy": 'cobol',
  "css": 'css',
  "csv": 'csv',
  "clj": 'clojure',
  "boot": 'clojure',
  "cl2": 'clojure',
  "cljc": 'clojure',
  "cljs": 'clojure',
  "cljs.hl": 'clojure',
  "cljscm": 'clojure',
  "cljx": 'clojure',
  "hic": 'clojure',
  "coffee": 'coffeescript',
  "_coffee": 'coffeescript',
  "cjsx": 'coffeescript',
  "cson": 'coffeescript',
  "iced": 'coffeescript',
  "lisp": 'lisp',
  "asd": 'lisp',
  "cl": 'opencl',
  "l": 'lisp',
  "lsp": 'lisp',
  "ny": 'lisp',
  "podsl": 'lisp',
  "sexp": 'lisp',
  "cps": 'pascal',
  "coq": 'coq',
  "v": 'verilog',
  "cr": 'crystal',
  "d": 'makefile',
  "di": 'd',
  "zone": 'dns-zone-file',
  "arpa": 'dns-zone-file',
  "dart": 'dart',
  "diff": 'diff',
  "patch": 'diff',
  "dockerfile": 'docker',
  "djs": 'docker',
  "e": 'eiffel',
  "ex": 'elixir',
  "exs": 'elixir',
  "elm": 'elm',
  "el": 'lisp',
  "emacs": 'lisp',
  "emacs.desktop": 'lisp',
  "erl": 'erlang',
  "es": 'javascript',
  "escript": 'erlang',
  "hrl": 'erlang',
  "xrl": 'erlang',
  "yrl": 'erlang',
  "fs": 'glsl',
  "fsi": 'fsharp',
  "fsx": 'fsharp',
  "fx": 'hlsl',
  "f90": 'fortran',
  "f03": 'fortran',
  "f08": 'fortran',
  "f77": 'fortran',
  "f95": 'fortran',
  "fpp": 'fortran',
  "factor": 'factor',
  "fr": 'text',
  "g": 'gap',
  "gco": 'gcode',
  "gcode": 'gcode',
  "gap": 'gap',
  "gd": 'gdscript',
  "gi": 'gap',
  "ms": 'maxscript',
  "glsl": 'glsl',
  "fp": 'glsl',
  "frag": 'javascript',
  "frg": 'glsl',
  "fsh": 'glsl',
  "fshader": 'glsl',
  "geo": 'glsl',
  "geom": 'glsl',
  "glslv": 'glsl',
  "gshader": 'glsl',
  "shader": 'glsl',
  "vert": 'glsl',
  "vrx": 'glsl',
  "vsh": 'glsl',
  "vshader": 'glsl',
  "gml": 'xml-doc',
  "po": 'gettext',
  "pot": 'gettext',
  "go": 'go',
  "gs": 'javascript',
  "graphql": 'graphql',
  "dot": 'dot',
  "gv": 'dot',
  "groovy": 'groovy',
  "grt": 'groovy',
  "gtpl": 'groovy',
  "gvy": 'groovy',
  "gsp": 'groovy',
  "hcl": 'hcl',
  "tf": 'hcl',
  "hlsl": 'hlsl',
  "fxh": 'hlsl',
  "hlsli": 'hlsl',
  "html": 'cshtml',
  "htm": 'cshtml',
  "html.hl": 'cshtml',
  "st": 'smalltalk',
  "xht": 'cshtml',
  "xhtml": 'cshtml',
  "mustache": 'cshtml',
  "jinja": 'cshtml',
  "eex": 'cshtml',
  "erb": 'cshtml',
  "erb.deface": 'cshtml',
  "phtml": 'php',
  "http": 'http',
  "php": 'php',
  "haml": 'haml',
  "haml.deface": 'haml',
  "handlebars": 'handlebars',
  "hbs": 'handlebars',
  "hs": 'haskell',
  "hsc": 'haskell',
  "hx": 'haxe',
  "hxsl": 'haxe',
  "ini": 'ini',
  "cfg": 'ini',
  "prefs": 'ini',
  "properties": 'ini',
  "idr": 'idris',
  "lidr": 'idris',
  "ni": 'inform7',
  "i7x": 'inform7',
  "io": 'io',
  "ijs": 'j',
  "json": 'json',
  "geojson": 'json',
  "lock": 'json',
  "topojson": 'json',
  "json5": 'json5',
  "jsx": 'jsx',
  "j": 'j',
  "java": 'java',
  "js": 'javascript',
  "_js": 'javascript',
  "bones": 'javascript',
  "es6": 'javascript',
  "jake": 'javascript',
  "jsb": 'javascript',
  "jscad": 'javascript',
  "jsfl": 'javascript',
  "jsm": 'javascript',
  "jss": 'javascript',
  "njs": 'javascript',
  "pac": 'javascript',
  "sjs": 'javascript',
  "ssjs": 'javascript',
  "sublime-build": 'javascript',
  "sublime-commands": 'javascript',
  "sublime-completions": 'javascript',
  "sublime-keymap": 'javascript',
  "sublime-macro": 'javascript',
  "sublime-menu": 'javascript',
  "sublime-mousemap": 'javascript',
  "sublime-project": 'javascript',
  "sublime-settings": 'javascript',
  "sublime-theme": 'javascript',
  "sublime-workspace": 'javascript',
  "sublime_metrics": 'javascript',
  "sublime_session": 'javascript',
  "xsjs": 'javascript',
  "xsjslib": 'javascript',
  "jl": 'julia',
  "kt": 'kotlin',
  "ktm": 'kotlin',
  "kts": 'kotlin',
  "ll": 'llvm',
  "lol": 'lolcode',
  "latte": 'latte',
  "less": 'less',
  "ly": 'lilypond',
  "ily": 'lilypond',
  "m": 'objectivec',
  "ld": 'linker-script',
  "lds": 'linker-script',
  "liquid": 'liquid',
  "lagda": 'agda',
  "litcoffee": 'coffeescript',
  "lhs": 'haskell',
  "_ls": 'livescript',
  "lua": 'lua',
  "fcgi": 'bash',
  "nse": 'lua',
  "pd_lua": 'lua',
  "rbxs": 'lua',
  "wlua": 'lua',
  "mcr": 'maxscript',
  "mtml": 'cshtml',
  "mak": 'makefile',
  "mk": 'makefile',
  "mkfile": 'makefile',
  "md": 'markdown',
  "markdown": 'markdown',
  "mkd": 'markdown',
  "mkdn": 'markdown',
  "mkdown": 'markdown',
  "ron": 'markdown',
  "nb": 'text',
  "matlab": 'matlab',
  "maxpat": 'maxscript',
  "maxhelp": 'maxscript',
  "maxproj": 'maxscript',
  "mxt": 'maxscript',
  "pat": 'maxscript',
  "mediawiki": 'wiki',
  "wiki": 'wiki',
  "monkey": 'monkey',
  "moon": 'moonscript',
  "ncl": 'text',
  "nl": 'lisp',
  "nsi": 'nsis',
  "nsh": 'nsis',
  "nginxconf": 'nginx',
  "nim": 'nim',
  "nimrod": 'nim',
  "nix": 'nix',
  "ml": 'ocaml',
  "eliom": 'ocaml',
  "eliomi": 'ocaml',
  "ml4": 'ocaml',
  "mli": 'ocaml',
  "mll": 'ocaml',
  "mly": 'ocaml',
  "mm": 'xml-doc',
  "opencl": 'opencl',
  "oz": 'oz',
  "aw": 'php',
  "ctp": 'php',
  "php3": 'php',
  "php4": 'php',
  "php5": 'php',
  "phps": 'php',
  "phpt": 'php',
  "pls": 'plsql',
  "pck": 'plsql',
  "pkb": 'plsql',
  "pks": 'plsql',
  "plb": 'plsql',
  "plsql": 'plsql',
  "sql": 'sql',
  "pas": 'pascal',
  "dfm": 'pascal',
  "dpr": 'pascal',
  "lpr": 'pascal',
  "pp": 'puppet',
  "pl": 'prolog',
  "al": 'perl',
  "cgi": 'bash',
  "perl": 'perl',
  "ph": 'perl',
  "plx": 'perl',
  "pm": 'perl',
  "pod": 'Pod',
  "psgi": 'perl',
  "6pl": 'perl',
  "6pm": 'perl',
  "nqp": 'perl',
  "p6": 'perl',
  "p6l": 'perl',
  "p6m": 'perl',
  "pl6": 'perl',
  "pm6": 'perl',
  "ps1": 'powershell',
  "psd1": 'powershell',
  "psm1": 'powershell',
  "pde": 'processing',
  "prolog": 'prolog',
  "yap": 'prolog',
  "proto": 'protobuf',
  "pb": 'purebasic',
  "pbi": 'purebasic',
  "purs": 'purescript',
  "py": 'python',
  "bzl": 'python',
  "gyp": 'python',
  "lmi": 'python',
  "pyde": 'python',
  "pyp": 'python',
  "pyt": 'python',
  "pyw": 'python',
  "tac": 'python',
  "wsgi": 'python',
  "xpy": 'python',
  "qml": 'qml',
  "qbs": 'qml',
  "rd": 'r',
  "rsx": 'r',
  "rhtml": 'cshtml',
  "rmd": 'markdown',
  "rkt": 'racket',
  "rktd": 'racket',
  "rktl": 'racket',
  "scrbl": 'racket',
  "rs": 'rust',
  "robot": 'robotframework',
  "rb": 'ruby',
  "builder": 'ruby',
  "gemspec": 'ruby',
  "god": 'ruby',
  "irbrc": 'ruby',
  "jbuilder": 'ruby',
  "mspec": 'ruby',
  "pluginspec": 'xml-doc',
  "podspec": 'ruby',
  "rabl": 'ruby',
  "rake": 'ruby',
  "rbuild": 'ruby',
  "rbw": 'ruby',
  "rbx": 'ruby',
  "ru": 'ruby',
  "ruby": 'ruby',
  "thor": 'ruby',
  "watchr": 'ruby',
  "rs.in": 'rust',
  "sas": 'sas',
  "scss": 'scss',
  "smt2": 'scss',
  "sparql": 'sparql',
  "rq": 'sparql',
  "sqf": 'sqf',
  "hqf": 'sqf',
  "cql": 'sql',
  "ddl": 'sql',
  "prc": 'sql',
  "tab": 'sql',
  "udf": 'sql',
  "viw": 'sql',
  "db2": 'sql',
  "sls": 'scheme',
  "sass": 'sass',
  "scala": 'scala',
  "sbt": 'scala',
  "scm": 'scheme',
  "sld": 'scheme',
  "sps": 'scheme',
  "ss": 'scheme',
  "sh": 'bash',
  "bash": 'bash',
  "bats": 'bash',
  "command": 'bash',
  "ksh": 'bash',
  "sh.in": 'bash',
  "tmux": 'bash',
  "tool": 'bash',
  "zsh": 'bash',
  "sh-session": 'shell-session',
  "smali": 'smali',
  "tpl": 'smarty',
  "nut": 'squirrel',
  "stan": 'stan',
  "do": 'stata',
  "ado": 'stata',
  "doh": 'stata',
  "ihlp": 'stata',
  "mata": 'stata',
  "matah": 'stata',
  "sthlp": 'stata',
  "styl": 'stylus',
  "scd": 'supercollider',
  "swift": 'swift',
  "sv": 'verilog',
  "svh": 'verilog',
  "vh": 'verilog',
  "toml": 'toml',
  "tcl": 'tcl',
  "adp": 'tcl',
  "tm": 'tcl',
  "tex": 'latex',
  "aux": 'latex',
  "bbx": 'latex',
  "bib": 'latex',
  "cbx": 'latex',
  "dtx": 'latex',
  "ins": 'latex',
  "lbx": 'latex',
  "ltx": 'latex',
  "mkii": 'latex',
  "mkiv": 'latex',
  "mkvi": 'latex',
  "sty": 'latex',
  "toc": 'latex',
  "txt": 'text',
  "no": 'text',
  "textile": 'textile',
  "ttl": 'turtle',
  "twig": 'twig',
  "ts": 'typescript',
  "tsx": 'jsx',
  "uc": 'unrealscript',
  "vhdl": 'vhdl',
  "vhd": 'vhdl',
  "vhf": 'vhdl',
  "vhi": 'vhdl',
  "vho": 'vhdl',
  "vhs": 'vhdl',
  "vht": 'vhdl',
  "vhw": 'vhdl',
  "vala": 'vala',
  "vapi": 'vala',
  "veo": 'Verilog',
  "vim": 'VimL',
  "vb": 'visual-basic',
  "bas": 'visual-basic',
  "frm": 'visual-basic',
  "frx": 'visual-basic',
  "vba": 'visual-basic',
  "vbhtml": 'visual-basic',
  "vbs": 'visual-basic',
  "xml": 'xml-doc',
  "ant": 'xml-doc',
  "axml": 'xml-doc',
  "ccxml": 'xml-doc',
  "clixml": 'xml-doc',
  "cproject": 'xml-doc',
  "csl": 'xml-doc',
  "csproj": 'xml-doc',
  "ct": 'xml-doc',
  "dita": 'xml-doc',
  "ditamap": 'xml-doc',
  "ditaval": 'xml-doc',
  "dll.config": 'xml-doc',
  "dotsettings": 'xml-doc',
  "filters": 'xml-doc',
  "fsproj": 'xml-doc',
  "fxml": 'xml-doc',
  "glade": 'xml-doc',
  "grxml": 'xml-doc',
  "iml": 'xml-doc',
  "ivy": 'xml-doc',
  "jelly": 'xml-doc',
  "jsproj": 'xml-doc',
  "kml": 'xml-doc',
  "launch": 'xml-doc',
  "mdpolicy": 'xml-doc',
  "mxml": 'xml-doc',
  "nproj": 'xml-doc',
  "nuspec": 'xml-doc',
  "odd": 'xml-doc',
  "osm": 'xml-doc',
  "plist": 'xml-doc',
  "props": 'xml-doc',
  "ps1xml": 'xml-doc',
  "psc1": 'xml-doc',
  "pt": 'xml-doc',
  "rdf": 'xml-doc',
  "rss": 'xml-doc',
  "scxml": 'xml-doc',
  "srdf": 'xml-doc',
  "storyboard": 'xml-doc',
  "stTheme": 'xml-doc',
  "sublime-snippet": 'xml-doc',
  "targets": 'xml-doc',
  "tmCommand": 'xml-doc',
  "tml": 'xml-doc',
  "tmLanguage": 'xml-doc',
  "tmPreferences": 'xml-doc',
  "tmSnippet": 'xml-doc',
  "tmTheme": 'xml-doc',
  "ui": 'xml-doc',
  "urdf": 'xml-doc',
  "ux": 'xml-doc',
  "vbproj": 'xml-doc',
  "vcxproj": 'xml-doc',
  "vssettings": 'xml-doc',
  "vxml": 'xml-doc',
  "wsdl": 'xml-doc',
  "wsf": 'xml-doc',
  "wxi": 'xml-doc',
  "wxl": 'xml-doc',
  "wxs": 'xml-doc',
  "x3d": 'xml-doc',
  "xacro": 'xml-doc',
  "xaml": 'xml-doc',
  "xib": 'xml-doc',
  "xlf": 'xml-doc',
  "xliff": 'xml-doc',
  "xmi": 'xml-doc',
  "xml.dist": 'xml-doc',
  "xproj": 'xml-doc',
  "xsd": 'xml-doc',
  "xul": 'xml-doc',
  "zcml": 'xml-doc',
  "xquery": 'xquery',
  "xq": 'xquery',
  "xql": 'xquery',
  "xqm": 'xquery',
  "xqy": 'xquery',
  "xojo_code": 'xojo',
  "xojo_menu": 'xojo',
  "xojo_report": 'xojo',
  "xojo_script": 'xojo',
  "xojo_toolbar": 'xojo',
  "xojo_window": 'xojo',
  "yml": 'yaml',
  "reek": 'yaml',
  "rviz": 'yaml',
  "sublime-syntax": 'yaml',
  "syntax": 'yaml',
  "yaml": 'yaml',
  "yaml-tmlanguage": 'yaml',
  "yang": 'yang',
}));

export async function getLang(): Promise<string> {
  let filePath = await getFilePath();
  if (filePath.includes("/")) {
    const tmpList = filePath.split("/");
    filePath = tmpList[tmpList.length-1];
  } else if (filePath.includes("\\")) {
    const tmpList = filePath.split("\\");
    filePath = tmpList[tmpList.length-1];
  }
  if (filePath.includes(".")) {
    const pos = filePath.indexOf(".");
    const ext = filePath.substring(pos + 1);
    return (langExtMap.get(ext) ?? "text");
  }
  return "text";
}